const utils = require('../../util/utils');
const OpLogDao = require('../../dao/admin/opLogDao');

var OpLogService = module.exports;

OpLogService.saveOperateLog = function(log) {
    return OpLogDao.createLog(log);
};

OpLogService.getOperateLogs = function (keywords, start, length, cb) {
    OpLogDao.getLogByKeywords(keywords, start, length).then(data => {
        if (!data) {
            return utils.invokeCallback(cb, {error: 1, msg: '内部错误'});
        } else {
            return utils.invokeCallback(cb, null, data);
        }
    }).catch( err => {
        console.log('Unable to connect to the database:'+err.stack);
        return utils.invokeCallback(cb, {error: 1, msg: '内部错误'});
    });
};

OpLogService.deleteByIds = function (ids, cb) {
    OpLogDao.deleteLogs(ids).then(result => {
        return utils.invokeCallback(cb, null, result);
    }).catch(err => {
        console.log('Unable to connect to the database:'+err.stack);
        return utils.invokeCallback(cb, {error: 1, msg: '删除失败，请联系管理员'});
    });
};